home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / gfx / show / aMiPEG_1_1_src.lha / aMiPEG_1.1 / src / s24bit.s < prev    next >
Text File  |  1997-12-02  |  13KB  |  751 lines

  1. ;
  2. ; This source handles conversion from yuv to rgb space, which includes
  3. ; initialization of the conversion & clamp tables.
  4. ;
  5. ; Original routines are in 24bit.c, which mainly contained those lovely 
  6. ; just-perfectly-fit-for-assembler-kick-ass constructions.
  7. ;
  8. ; Michael Rausch  14-4-94  1:12:57
  9. ;
  10.  
  11.     SECTION    text,CODE
  12.  
  13. ;************************************************************************************
  14.  
  15. ; We'll define the "ConvertColor" macro here to do fixed point arithmetic
  16. ; that'll convert from YCrCb to RGB using:
  17. ;    R = L + 1.40200*Cr
  18. ;    G = L - 0.34414*Cb - 0.71414*Cr
  19. ;    B = L + 1.77200*Cb
  20. ;
  21.  
  22. ; void InitColorDither(void)
  23.     XDEF    @InitColorDither
  24. @InitColorDither:            
  25.  
  26.     lea    Cb_r_tab,a0
  27. Cr_gb_off EQU    256*4
  28.     lea    Cb_r_tab+Cr_gb_off,a1
  29.  
  30.     move.w    #255,d0
  31.     moveq    #-128,d1
  32. crgbtabs:
  33.     move.w    d1,d2
  34.     muls.w    #179,d2        ; 1.40200
  35.     asr.w    #7,d2
  36.     add.w    d2,d2
  37.     move.w    d2,(a0)+    ;br
  38.     move.w    d1,d2
  39.     muls.w    #-91,d2        ; -0.71414
  40.     asr.w    #7,d2
  41.     add.w    d2,d2
  42.     move.w    d2,(a1)+    ;bg
  43.     move.w    d1,d2
  44.     muls.w    #-44,d2        ; -0.34414
  45.     asr.w    #7,d2
  46.     add.w    d2,d2
  47.     move.w    d2,(a0)+    ;rg
  48.     move.w    d1,d2
  49.     muls.w    #226,d2        ; 1.77200
  50.     asr.w    #7,d2
  51.     add.w    d2,d2
  52.     move.w    d2,(a1)+    ;rb
  53.     addq.l    #1,d1
  54.     dbra    d0,crgbtabs
  55.  
  56. ;
  57. ; create the clamp tables, including the shifted one
  58. ;
  59. ; IMPORTANT: The first versions had a MUCH too low clampsize, resulting in really
  60. ; annoying purple artifacts !!!
  61. ;
  62. clampsize EQU    192
  63.  
  64.     moveq    #0,d1
  65.     lea    _clamp-clampsize*2,a0            ; clear lower and upper 64 bytes
  66.     move.w    #clampsize-1,d0
  67. fill_ct1:move.w    #$ff00,((clampsize+256)*2,a0)
  68.     move.w    d1,(a0)+
  69.     dbra    d0,fill_ct1
  70.     move.w    #255,d0
  71. fill_ct2:move.w    d1,(a0)+
  72.     add.w    #$100,d1
  73.     dbra    d0,fill_ct2
  74.  
  75.     rts
  76.  
  77. ;************************************************************************************
  78.  
  79. ;void ColorDitherImage(unsigned char *lum, unsigned char *cr, unsigned char *cb,
  80. ;              unsigned char *out, int rows, int cols)
  81.     XDEF @ColorDitherImage_lores
  82. @ColorDitherImage_lores:
  83.  
  84. ;    a0  unsigned char *lum
  85. ;    a1  unsigned char *cr
  86. ; 4(sp)  unsigned char *cb
  87. ; 8(sp)  unsigned char *out
  88. ;    d0  int rows
  89. ;    d1  int cols
  90.  
  91. cdi_regs REG    d2-d7/a2-a6    ; 6+5=11
  92.     movem.l    cdi_regs,-(sp)
  93.  
  94. ;saved7    EQU    0
  95. saverows EQU    4
  96. savecols EQU    8
  97. localvars EQU    savecols+4
  98. cb_offset EQU    localvars+11*4+4
  99. out_offset EQU    cb_offset+4
  100.  
  101.     sub.w    #localvars,sp
  102.  
  103.     move.l    d1,(savecols,sp)
  104.     lsr.l    #1,d0
  105.     subq.l    #1,d0
  106.     move.l    d0,d7
  107.  
  108.     move.l    a0,a2            ; lum1
  109.     move.l    a2,a3
  110.     add.l    d1,a3            ; lum2 = lum1+cols
  111.  
  112.     move.l    a1,a4            ; cr channel
  113.     move.l    cb_offset(sp),d5
  114.     sub.l    a4,d5            ; cb channel is addressed via its offset to the cr channel
  115.  
  116.     lea    Cb_r_tab,a5        ; conversion tab(s)
  117.  
  118.     move.l    (out_offset,sp),a0    ; row1
  119.     move.l    a0,a1
  120.     add.l    d1,d1            
  121.     add.l    d1,a1            ; row2=row1+cols*2
  122.  
  123. all_rows_lores:
  124.     move.l    (savecols,sp),d6
  125.     lsr.l    #1,d6
  126.     subq.l    #1,d6
  127. all_cols_lores:
  128.  
  129. ; free: d4
  130.  
  131.     moveq    #0,d1
  132.     moveq    #0,d2
  133.     move.b    (a4,d5.l),d1        ; CB channel
  134.     move.b    (a4)+,d2        ; CR channel
  135.  
  136.     move.l    (a5,d1.w*4),d0            ; cb_r cb_g
  137.     move.l    (Cr_gb_off,a5,d2.w*4),d1    ; cr_g cr_b
  138.  
  139.     move.w    d1,d2
  140.     swap    d1
  141.     add.w    d0,d1
  142.     swap     d0
  143.  
  144.  
  145.     sub.w    d1,d0
  146.     sub.w    d1,d2
  147.  
  148.     ext.l    d1
  149.     add.l    #_clamp,d1
  150.  
  151. ; d0   cb_r      *2
  152. ; d1  (cr_g+cb_g) *2
  153. ; d2   cr_b      *2
  154.  
  155.     moveq    #0,d3            ; *lum++
  156.     move.b    (a2)+,d3
  157.     move.l    d1,a6            ; clamp table includes on L
  158.     add.l    d3,d3
  159.     add.l    d3,a6
  160.     move.w    (a6,d0.w),d3        ; r
  161.     or.b    (a6),d3            ; g
  162.  
  163.     swap    d3
  164.  
  165.     move.b    (a2)+,d3        ; *lum++
  166.     move.l    d1,a6            ; clamp table includes on L
  167.     add.w    d3,d3
  168.     add.w    d3,a6
  169.     move.w    (a6,d2.w),d3        ; b
  170.     or.b    (a6),d3            ; g
  171.  
  172.     move.l    d3,(a0)+        ; *row1++
  173.  
  174.  
  175.  
  176.     moveq    #0,d3            ; *lum++
  177.     move.b    (a3)+,d3
  178.     move.l    d1,a6            ; clamp table includes on L
  179.     add.l    d3,d3
  180.     add.l    d3,a6
  181.     move.w    (a6,d0.w),d3        ; r
  182.     move.b    (a6),d3            ; g
  183.  
  184.     swap    d3
  185.  
  186.     move.b    (a3)+,d3        ; *lum++
  187.     move.l    d1,a6            ; clamp table includes on L
  188.     add.w    d3,d3
  189.     add.w    d3,a6
  190.     move.w    (a6,d2.w),d3        ; b
  191.     move.b    (a6),d3            ; g
  192.  
  193.     move.l    d3,(a1)+        ; *row1++
  194.  
  195.  
  196.  
  197.     dbra    d6,all_cols_lores
  198.  
  199.     move.l    savecols(sp),d0        ; next line in the luminance channel
  200.     add.l    d0,a2
  201.     add.l    d0,a3
  202.  
  203.     add.l    d0,d0            ; 2 bytes per pixel
  204.     add.l    d0,a0            ; next line in the output row
  205.     add.l    d0,a1
  206.  
  207.     dbra    d7,all_rows_lores
  208.  
  209.     add.w    #localvars,sp
  210.     movem.l    (sp)+,cdi_regs
  211.     rts
  212.  
  213. ;************************************************************************************
  214.     XDEF @ColorDitherImage_VideoLayerYCbCr
  215.  
  216. ;    a0  unsigned char *lum
  217. ;    a1  unsigned char *cr
  218. ; 4(sp)  unsigned char *cb
  219. ; 8(sp)  unsigned char *out
  220. ;    d0  int rows
  221. ;    d1  int cols
  222.  
  223. cb_off2    EQU    11*4+4
  224. out_off2    EQU    cb_off2+4
  225.  
  226. @ColorDitherImage_VideoLayerYCbCr:
  227.  
  228.     movem.l    cdi_regs,-(sp)
  229.  
  230.     move.l    cb_off2(sp),a2
  231.     move.l    out_off2(sp),a3
  232.  
  233.     lea    (a0,d1.w),a5
  234.     lea    (a3,d1.w*2),a4
  235.  
  236.     move.l    d1,d4
  237.     lsl.l    #1,d4
  238.  
  239.     lsr.w    #1,d0
  240.     sub.w    #1,d0
  241.  
  242. all_rows_VL
  243.     move.l    d1,d5
  244.     lsr.w    #1,d5
  245.     sub.w    #1,d5
  246.  
  247. column_VL
  248.     move.b    (a1)+,d2
  249.     move.b    (a0)+,d3
  250.     lsl.w    #8,d3
  251.     move.b    d2,d3
  252.     move.w    d3,(a3)+
  253.  
  254.     move.b    (a5)+,d3
  255.     lsl.w    #8,d3
  256.     move.b    d2,d3
  257.     move.w    d3,(a4)+
  258.  
  259.     move.b    (a2)+,d2
  260.     move.b    (a0)+,d3
  261.     lsl.w    #8,d3
  262.     move.b    d2,d3
  263.     move.w    d3,(a3)+
  264.  
  265.     move.b    (a5)+,d3
  266.     lsl.w    #8,d3
  267.     move.b    d2,d3
  268.     move.w    d3,(a4)+
  269.  
  270.     dbf    d5,column_VL
  271.  
  272.     add.l    d1,a0
  273.     add.l    d1,a5
  274.  
  275.     add.l    d4,a3
  276.     add.l    d4,a4
  277.  
  278.     dbf    d0,all_rows_VL
  279.  
  280.     movem.l    (sp)+,cdi_regs
  281.     rts
  282.  
  283. ;************************************************************************************
  284.     XDEF @ColorDitherImage_VideoLayerGray
  285.  
  286. ;    a0  unsigned char *lum
  287. ;    a1  unsigned char *cr
  288. ; 4(sp)  unsigned char *cb
  289. ; 8(sp)  unsigned char *out
  290. ;    d0  int rows
  291. ;    d1  int cols
  292.  
  293. @ColorDitherImage_VideoLayerGray:
  294.  
  295.     movem.l    cdi_regs,-(sp)
  296.  
  297.     move.l    out_off2(sp),a3
  298.  
  299.     lea    (a0,d1.w),a5
  300.     lea    (a3,d1.w*2),a4
  301.  
  302.     move.l    d1,d4
  303.     lsl.l    #1,d4
  304.  
  305.     lsr.w    #1,d0
  306.     sub.w    #1,d0
  307.  
  308.     move.b    #$80,d2
  309.  
  310. all_rows_VLG
  311.     move.l    d1,d5
  312.     lsr.w    #1,d5
  313.     sub.w    #1,d5
  314.  
  315. column_VLG
  316.     move.b    (a0)+,d3
  317.     lsl.w    #8,d3
  318.     move.b    d2,d3
  319.     lsl.l    #8,d3
  320.     move.b    (a0)+,d3
  321.     lsl.l    #8,d3
  322.     move.b    d2,d3
  323.  
  324.     move.l    d3,(a3)+
  325.  
  326.     move.b    (a5)+,d3
  327.     lsl.w    #8,d3
  328.     move.b    d2,d3
  329.     lsl.l    #8,d3
  330.     move.b    (a5)+,d3
  331.     lsl.l    #8,d3
  332.     move.b    d2,d3
  333.  
  334.     move.l    d3,(a4)+
  335.  
  336.     dbf    d5,column_VLG
  337.  
  338.     add.l    d1,a0
  339.     add.l    d1,a5
  340.  
  341.     add.l    d4,a3
  342.     add.l    d4,a4
  343.  
  344.     dbf    d0,all_rows_VLG
  345.  
  346.     movem.l    (sp)+,cdi_regs
  347.     rts
  348.  
  349. ;************************************************************************************
  350.     XDEF @ColorDitherImage_RGB
  351. ;    a0  unsigned char *lum
  352. ;    a1  unsigned char *cr
  353. ; 4(sp)  unsigned char *cb
  354. ; 8(sp)  unsigned char *out
  355. ;    d0  int rows
  356. ;    d1  int cols
  357.  
  358. @ColorDitherImage_RGB:
  359.     movem.l    cdi_regs,-(sp)
  360.  
  361.     sub.w    #localvars,sp
  362.     move.l    d1,(savecols,sp)
  363.     lsr.l    #1,d0
  364.     subq.l    #1,d0
  365.     move.l    d0,d7
  366.  
  367.     move.l    a0,a2            ; lum1
  368.     move.l    a2,a3
  369.  
  370.     add.l    d1,a3            ; lum2 = lum1+cols
  371.  
  372.     move.l    a1,a4            ; cr channel
  373.     move.l    cb_offset(sp),d5
  374.     sub.l    a4,d5            ; cb channel is addressed via its offset to the cr channel
  375.  
  376.     lea    Cb_r_tab,a5        ; conversion tab(s)
  377.  
  378.     move.l    (out_offset,sp),a0    ; row1
  379.     move.l    a0,a1
  380.  
  381.     lsl.l    #2,d1
  382.     add.l    d1,a1            ; row2=row1+cols*4
  383.  
  384.     move.l    (savecols,sp),d4
  385. all_rows_rgb:
  386.     move.w    d4,d6
  387.     lsr.w    #1,d6
  388.     subq.w    #1,d6
  389. all_cols_rgb:
  390.  
  391. ; still free: d4
  392.  
  393.     moveq    #0,d1
  394.     moveq    #0,d2
  395.     move.b    (a4,d5.l),d1        ; CB channel
  396.     move.b    (a4)+,d2        ; CR channel
  397.  
  398.     move.l    (a5,d1.w*4),d0            ; cb_r cb_g
  399.     move.l    (Cr_gb_off,a5,d2.w*4),d1    ; cr_g cr_b
  400.  
  401.     move.w    d1,d2
  402.     swap    d1
  403.     add.w    d0,d1
  404.     swap     d0
  405.  
  406.     sub.w    d2,d0
  407.     sub.w    d2,d1
  408.  
  409.     ext.l    d2
  410.     add.l    #_clamp,d2
  411.  
  412.     exg        a4,d2
  413.  
  414. ; d0   cb_r      *2
  415. ; d1  (cr_g+cb_g) *2
  416. ; d2   cr_b      *2
  417.  
  418. ;    moveq    #0,d3            ; *lum++
  419.     clr.w    d3
  420.     move.b    (a2)+,d3
  421.     lea    (a4,d3.w*2),a6
  422.  
  423. ;    move.b    (a6,d0.w),d3
  424. ;    swap    d3
  425.     move.l    -1(a6,d0.w),d3
  426.     move.w    (a6,d1.w),d3
  427.     move.b    (a6),d3
  428.     move.l    d3,(a0)+
  429.  
  430. ;    moveq    #0,d3            ; *lum++
  431.     clr.w    d3
  432.     move.b    (a2)+,d3
  433.     lea    (a4,d3.w*2),a6
  434.  
  435. ;    move.b    (a6,d0.w),d3
  436. ;    swap    d3
  437.     move.l    -1(a6,d0.w),d3
  438.     move.w    (a6,d1.w),d3
  439.     move.b    (a6),d3
  440.     move.l    d3,(a0)+
  441.  
  442. ;    moveq    #0,d3            ; *lum2++
  443.     clr.w    d3
  444.     move.b    (a3)+,d3
  445.     lea    (a4,d3.w*2),a6
  446.  
  447. ;    move.b    (a6,d0.w),d3
  448. ;    swap    d3
  449.     move.l    -1(a6,d0.w),d3
  450.     move.w    (a6,d1.w),d3
  451.     move.b    (a6),d3
  452.     move.l    d3,(a1)+
  453.  
  454. ;    moveq    #0,d3            ; *lum2++
  455.     clr.w    d3
  456.     move.b    (a3)+,d3
  457.     lea    (a4,d3.w*2),a6
  458.  
  459. ;    move.b    (a6,d0.w),d3
  460. ;    swap    d3
  461.     move.l    -1(a6,d0.w),d3
  462.     move.w    (a6,d1.w),d3
  463.     move.b    (a6),d3
  464.     move.l    d3,(a1)+
  465.  
  466.     move.l    d2,a4
  467.  
  468.     dbra    d6,all_cols_rgb
  469.  
  470.     move.l    d4,d0        ; next line in the luminance channel
  471.  
  472.     add.l    d0,a2
  473.     add.l    d0,a3
  474.  
  475.     lsl.l    #2,d0            ; 4 bytes per pixel
  476.     add.l    d0,a0            ; next line in the output row
  477.     add.l    d0,a1
  478.  
  479.     dbra    d7,all_rows_rgb
  480.  
  481.     add.w    #localvars,sp
  482.     movem.l    (sp)+,cdi_regs
  483.     rts
  484.  
  485.  
  486. ;********************